﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Xml;
using SharpObjects.Configuration;
using SharpObjects.Configuration.ConfigurationProviders;
using SharpObjects.Interfaces;
using SharpObjects.RuleEngine;

namespace SharpRuleEngineTest.RuleElements
{
    public class ValueElement : IInitializable
    {
        public object Value { get; set; }

        public eFieldType ValueType { get; set; }


        #region IInitializable Members

        public void Initialize(XmlElement initializationElement)
        {
            XmlConfigurationProvider init = new XmlConfigurationProvider(initializationElement);

            ValueType = init.GetEnum<eFieldType>("@type", eFieldType.String);

            switch (ValueType)
            {
                case eFieldType.String:
                    Value = init.GetString("self::*");
                    break;
                case eFieldType.Int:
                    Value = init.GetInteger("self::*");
                    break;
                case eFieldType.Double:
                    Value = init.GetDouble("self::*");
                    break;
                case eFieldType.DateTime:
                    Value = init.GetDateTime("self::*");
                    break;
                case eFieldType.Bool:
                    Value = init.GetBoolean("self::*");
                    break;
                default:
                    throw new ArgumentException("Unknown eFieldType enum value: " + ValueType);
            }
        }

        #endregion
    }
}
